<script type="text/javascript">
        window.addEvent('domready',function(){
				$('commodity_category').addEvent('change',function(){
					$('commodity_commodity').set('value','0');
					$('commodities_index').submit();
				});
				
				$('commodity_commodity').addEvent('change',function(){
					$('commodity_type').set('value','0');
					$('commodities_index').submit();
				});
				
				$('commodity_type').addEvent('change',function(){
					$('commodities_index').submit();
				});
				
				var modal;

				modal = new FbModal({
					'parentEl': 'outerWrapper', 
					'content': "<?=site_url()?>commodities/commodity_add",
					'height' : 600,
					'width' : 600
				});
		
		
				$('add_commodity').addEvent('click',function(){
					modal.drawModal();
				});
        });
</script>	
    <div id="leftColumnside">
        <div class="secureContent">
		<?php
				$this->mytemplate->getsecuresubmenu($userinfo['UserId'],3);
				$attr = array('id' => 'commodities_index');
		?>
		<?=form_open('commodities/index',$attr)?>	
			
            <hr width="100%" />
            <br />
            <h3>Pencarian Komoditi</h3>
            <br />
            <div class="box" align="center">
          Kategori :
          <select name="kategori" id="commodity_category">
                  <option value="0">-Pilih Kategori Komoditas-</option>
          <?php
					foreach($category as $cat)
                    {
							if($cat['CategoryId'] == $formvalue['kategori']){
								echo "<option value=".$cat['CategoryId']." selected='selected'>".$cat['CategoryName']."</option>";
							}else{
								echo "<option value=".$cat['CategoryId'].">".$cat['CategoryName']."</option>";
							}
                    }
          ?>
          </select>
          Komoditas : <select name="komoditas" id='commodity_commodity'>
          <option value="0">-Pilih Komoditas-</option>
          <?php
				if(count($commodityname) > 0){
					foreach($commodityname as $cn)
                    {
							if($cn['CommodityId'] == $formvalue['komoditas']){
								echo "<option value=".$cn['CommodityId']." selected='selected'>".$cn['CommodityName']."</option>";
							}else{
								echo "<option value=".$cn['CommodityId'].">".$cn['CommodityName']."</option>";
							}
                    }
				}
          ?>
          </select>
          Jenis : <select name="jenis" id='commodity_type'>
          <option value="0">-Pilih Jenis Komoditas-</option>
          <?php
				if(count($commoditytype) > 0){
					foreach($commoditytype as $ct)
                    {
							if($ct['CommodityTypeId'] == $formvalue['jenis']){
								echo "<option value=".$ct['CommodityTypeId']." selected='selected'>".$ct['CommodityTypeName']."</option>";
							}else{
								echo "<option value=".$ct['CommodityTypeId'].">".$ct['CommodityTypeName']."</option>";
							}
                    }
				}
          ?>
          </select>
          <input type="button" value="Cari"/>
            </div><br />
            <h3>Daftar Komoditi</h3>
            <div class='right' style='padding:5px;'>
				<a href='#' id='add_commodity'>TAMBAH KOMODITI</a>
			</div>	
            <br />
            <?php if(count($commodity) > 0){ ?>
            <table width="100%" border="1" cellpadding="4">
            <tr align="center">
                <th width="20">No</th>
                <th width="80">Kategori</th>
                <th width="80">Komoditi</th>
                <th width="80">Jenis Komoditi</th>
                <th width="80">Lokasi</th>
                <th width="80">Kuantitas</th>
                <th width="50">Satuan</th>
                <th width="100">Tanggal Komoditi Tersedia</th>
                <th width="100">Aksi</th>
           </tr>
            <?php
                            $index = 1;
                            foreach($commodity as $com)
                            {
                                    
                                    echo "<tr>
                                            <td>".$index++."</td>
                                            <td>".$com['CategoryName']."</td>
                                            <td>".$com['CommodityName']."</td>
                                            <td>".$com['CommodityTypeName']."</td>
                                            <td>".$com['RegencyName']."</td>
                                            <td>".$com['Quantity']."</td>
                                            <td>".$com['UOMName']."</td>
                                            <td>".$com['AvailableDate']."</td>
                                            <td align='center'><a href='javascript:void(0);'>Detail</a>&nbsp;&nbsp;
                                            <a href='javascript:void(0);'>Edit</a>&nbsp;&nbsp;
                                            <a href='javascript:void(0);'>Hapus</a></td>
                                    </tr>";
                            }

                    ?>
            </table>
            <?php }else{ ?>
				<table width="100%" border="1" cellpadding="4">
					<tr align="center">
						<th width="20">No</th>
						<th width="80">Kategori</th>
						<th width="80">Komoditi</th>
						<th width="80">Jenis Komoditi</th>
						<th width="80">Lokasi</th>
						<th width="80">Kuantitas</th>
						<th width="50">Satuan</th>
						<th width="100">Tanggal Komoditi Tersedia</th>
						<th width="100">Aksi</th>
					</tr>
					<tr>
						<td colspan="9">-Data tidak ditemukan-</td>
					</tr>
				</table>
			<?php } ?>
        <?=form_close();?>    
        </div>
    </div>
	
